package com.cyj.qqclient.view;

import com.cyj.qqclient.service.FileClientService;
import com.cyj.qqclient.service.MessageClientService;
import com.cyj.qqclient.service.UserClientService;

import java.util.Scanner;

public class QQView {
    private boolean loop=true;
    private String key="";
    private UserClientService userClientService=new UserClientService();//用于登录服务器


    public static void main(String[] args) throws InterruptedException {
        new QQView().mainMenu();
        System.out.println("退出系统！！！");
    }

    private void mainMenu() throws InterruptedException {
        Scanner scanner=new Scanner(System.in);

        while(loop){
            System.out.println("================欢迎登陆QQ用户端==================");
            System.out.println("\t\t\t\t 1 登录系统");
            System.out.println("\t\t\t\t 9 退出系统");
            System.out.println("请输入选择：");
            key=scanner.nextLine();
            Thread.sleep(100);
            switch (key){
                case "1":
                    System.out.println("请输入用户id:");
                    String ID=scanner.nextLine();
                    System.out.println("请输入密码：");
                    String password=scanner.nextLine();

                    //验证用户是否存在
                    if(userClientService.checkUser(ID,password)){
                        System.out.println("登录成功"+ID+"用户");
                        while(loop){
                            System.out.println("================"+"用户"+ID+"的QQ二级菜单==================");
                            System.out.println("\t\t\t\t 1 显示在线用户列表");
                            System.out.println("\t\t\t\t 2 群发消息");
                            System.out.println("\t\t\t\t 3 私聊消息");
                            System.out.println("\t\t\t\t 4 发送文件");
                            System.out.println("\t\t\t\t 9 退出系统");
                            System.out.println("请输入选择：");
                            key=scanner.nextLine();
                            switch (key){
                                case "1":
                                    System.out.println("显示用户在线列表");
                                    userClientService.onlineFriendList();
                                    break;
                                case "2":
                                    System.out.println("请输入要群发的消息：");
                                    //
                                    String content2=scanner.nextLine();
                                    MessageClientService.sendMessageToALL(content2,ID);
                                    break;
                                case "3":
                                    //进入聊天功能
                                    System.out.println("请输入想聊天的用户（在线）：");
                                    String getterid = scanner.nextLine();
                                    System.out.println("请输入消息内容：");
                                    String content = scanner.nextLine();
                                    MessageClientService.sendMessageToOne(content,ID,getterid);
                                    break;
                                case "4":
                                    System.out.println("请输入你想发送的用户：");
                                    String getterid2 = scanner.nextLine();
                                    System.out.println("请输入发送文件的路径：");
                                    String src = scanner.nextLine();
                                    System.out.println("请输入对方保存文件的路径：");
                                    String dest = scanner.nextLine();
                                    FileClientService.sendFile(src,dest,ID,getterid2);

                                    break;
                                case "9":
                                    userClientService.exitUserClient();
                                    loop=false;
                                    break;
                            }
                        }
                    }else {
                        System.out.println("登陆失败");
                    }
                    break;
                case "9":
                    System.out.println("退出");
                    //调用退出方法
                    userClientService.exitUserClient();
                    loop=false;
                    break;
            }
        }
    }
}
